package 数组查找.二分法查找.test02;

public class ArrayUtil {
    public static void main(String[] args) {
        int[] arr = {12,14,43,76,243,765,1000};
        binarySearch(arr,243);
    }

    public static void binarySearch(int[] arr, int i) {
        int begin = 0;
        int end = arr.length-1;
        while(begin <= end) {
            int mid = (begin + end) / 2;
            if (arr[mid] == i) {
                System.out.println(i + "在该数组 " + mid + " 下标上");
                return;
            } else if (arr[mid] < i) {
                begin = mid + 1;

            } else {
                end = mid - 1;
            }
        }
        System.out.println(i + "不在该数组");
        return;
    }
}
